﻿Imports System.Data.Entity
Imports HSPelections.Models

Public Class Default1Controller
    Inherits System.Web.Mvc.Controller

    Private db As New VoteNumsContext

    '
    ' GET: /Default1/

    Function Index() As ActionResult
        Return View(db.VoteNums.ToList())
    End Function

    '
    ' GET: /Default1/Details/5

    Function Details(Optional ByVal id As Integer = Nothing) As ActionResult
        Dim votenum As VoteNum = db.VoteNums.Find(id)
        If IsNothing(votenum) Then
            Return HttpNotFound()
        End If
        Return View(votenum)
    End Function

    '
    ' GET: /Default1/Create

    Function Create() As ActionResult
        Return View()
    End Function

    '
    ' POST: /Default1/Create

    <HttpPost()> _
    <ValidateAntiForgeryToken()> _
    Function Create(ByVal votenum As VoteNum) As ActionResult
        If ModelState.IsValid Then
            db.VoteNums.Add(votenum)
            db.SaveChanges()
            Return RedirectToAction("Index")
        End If

        Return View(votenum)
    End Function

    '
    ' GET: /Default1/Edit/5

    Function Edit(Optional ByVal id As Integer = Nothing) As ActionResult
        Dim votenum As VoteNum = db.VoteNums.Find(id)
        If IsNothing(votenum) Then
            Return HttpNotFound()
        End If
        Return View(votenum)
    End Function

    '
    ' POST: /Default1/Edit/5

    <HttpPost()> _
    <ValidateAntiForgeryToken()> _
    Function Edit(ByVal votenum As VoteNum) As ActionResult
        If ModelState.IsValid Then
            db.Entry(votenum).State = EntityState.Modified
            db.SaveChanges()
            Return RedirectToAction("Index")
        End If

        Return View(votenum)
    End Function

    '
    ' GET: /Default1/Delete/5

    Function Delete(Optional ByVal id As Integer = Nothing) As ActionResult
        Dim votenum As VoteNum = db.VoteNums.Find(id)
        If IsNothing(votenum) Then
            Return HttpNotFound()
        End If
        Return View(votenum)
    End Function

    '
    ' POST: /Default1/Delete/5

    <HttpPost()> _
    <ActionName("Delete")> _
    <ValidateAntiForgeryToken()> _
    Function DeleteConfirmed(ByVal id As Integer) As RedirectToRouteResult
        Dim votenum As VoteNum = db.VoteNums.Find(id)
        db.VoteNums.Remove(votenum)
        db.SaveChanges()
        Return RedirectToAction("Index")
    End Function

    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        db.Dispose()
        MyBase.Dispose(disposing)
    End Sub


    Function MakeVote4() As ActionResult
        Dim newVote As New MakeNumVote
        Dim newballet As List(Of Integer) = newVote.createVote()
        Dim i As Integer = 1
        For Each numbers In newballet
            If i = 1 Then
                If numbers = 0 Then
                    Dim res = db.VoteNums.Find(1)
                    res.President = res.President + 1
                ElseIf numbers = 1 Then
                    Dim res = db.VoteNums.Find(2)
                    res.President = res.President + 1
                ElseIf numbers = 2 Then
                    Dim res = db.VoteNums.Find(3)
                    res.President = res.President + 1
                ElseIf numbers = 3 Then
                    Dim res = db.VoteNums.Find(4)
                    res.President = res.President + 1
                ElseIf numbers = 4 Then
                    Dim res = db.VoteNums.Find(5)
                    res.President = res.President + 1
                End If
            ElseIf i = 2 Then
                If numbers = 0 Then
                    Dim res = db.VoteNums.Find(1)
                    res.VicePresident = res.VicePresident + 1
                ElseIf numbers = 1 Then
                    Dim res = db.VoteNums.Find(2)
                    res.VicePresident = res.VicePresident + 1
                ElseIf numbers = 2 Then
                    Dim res = db.VoteNums.Find(3)
                    res.VicePresident = res.VicePresident + 1
                ElseIf numbers = 3 Then
                    Dim res = db.VoteNums.Find(4)
                    res.VicePresident = res.VicePresident + 1
                ElseIf numbers = 4 Then
                    Dim res = db.VoteNums.Find(5)
                    res.VicePresident = res.VicePresident + 1
                End If
            ElseIf i = 3 Then
                If numbers = 0 Then
                    Dim res = db.VoteNums.Find(1)
                    res.Secretary = res.Secretary + 1
                ElseIf numbers = 1 Then
                    Dim res = db.VoteNums.Find(2)
                    res.Secretary = res.Secretary + 1
                ElseIf numbers = 2 Then
                    Dim res = db.VoteNums.Find(3)
                    res.Secretary = res.Secretary + 1
                ElseIf numbers = 3 Then
                    Dim res = db.VoteNums.Find(4)
                    res.Secretary = res.Secretary + 1
                ElseIf numbers = 4 Then
                    Dim res = db.VoteNums.Find(5)
                    res.Secretary = res.Secretary + 1
                End If
            ElseIf i = 4 Then
                If numbers = 0 Then
                    Dim res = db.VoteNums.Find(1)
                    res.Treasurer = res.Treasurer + 1
                ElseIf numbers = 1 Then
                    Dim res = db.VoteNums.Find(2)
                    res.Treasurer = res.Treasurer + 1
                ElseIf numbers = 2 Then
                    Dim res = db.VoteNums.Find(3)
                    res.Treasurer = res.Treasurer + 1
                ElseIf numbers = 3 Then
                    Dim res = db.VoteNums.Find(4)
                    res.Treasurer = res.Treasurer + 1
                ElseIf numbers = 4 Then
                    Dim res = db.VoteNums.Find(5)
                    res.Treasurer = res.Treasurer + 1
                End If
            ElseIf i = 5 Then
                If numbers = 0 Then
                    Dim res = db.VoteNums.Find(1)
                    res.SergeantAtArms = res.SergeantAtArms + 1
                ElseIf numbers = 1 Then
                    Dim res = db.VoteNums.Find(2)
                    res.SergeantAtArms = res.SergeantAtArms + 1
                ElseIf numbers = 2 Then
                    Dim res = db.VoteNums.Find(3)
                    res.SergeantAtArms = res.SergeantAtArms + 1
                ElseIf numbers = 3 Then
                    Dim res = db.VoteNums.Find(4)
                    res.SergeantAtArms = res.SergeantAtArms + 1
                ElseIf numbers = 4 Then
                    Dim res = db.VoteNums.Find(5)
                    res.SergeantAtArms = res.SergeantAtArms + 1
                End If
            End If
            db.SaveChanges()
            i = i + 1
        Next
        Return RedirectToAction("Index")
    End Function
    Function adjustNum(person, iValue)

    End Function
End Class